using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Utility;
using Entities;
using BUS;
using DAL;

public partial class Admin_MaSoSPList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDropDownList();
            LoadData();
        }
    }
    private void LoadDropDownList()
    {
        // load ct dh
        ddl_ct.DataSource = tbChiTietDHBUS .GetAll();
        ddl_ct.DataValueField = tbChiTietDH .tbChiTietDHColumns .IDCTDH .ToString();
        ddl_ct.DataBind();
        ddl_ct.Items.Insert(0, new ListItem("All", "0"));
    }
    private void LoadData()
    {
        Pager.PageSize = 5;
        Criteria c = new Criteria();

        if (txt_ms.Text != "")

            c.add(Condition.AND, tbMaSoSP.tbMaSoSPColumns .IDMSSP .ToString(), Condition.LIKE, txt_ms.Text);

        if (txt_tt.Text != "")

            c.add(Condition.AND, tbMaSoSP .tbMaSoSPColumns  .TrangThai .ToString(), Condition.LIKE, txt_tt.Text);

        int total = 0;
        tbMaSoSP .tbMaSoSPCollection   ht_Collection =
            tbMaSoSPBUS .Get(c.Criter, Pager.CurrentIndex, Pager.PageSize,
           tbMaSoSP.tbMaSoSPColumns.IDMSSP .ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = ht_Collection;
        Repeater1.DataBind();
        Pager.ItemCount = total;

    }
    protected void btn_Search_Click1(object sender, EventArgs e)
    {
        LoadData();
    }
    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        Pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            tbMaSoSP dd = (tbMaSoSP)e.Item.DataItem;
            HyperLink hyp_dd = (HyperLink)e.Item.FindControl("hyp_dd");
            HyperLink hyp_tt = (HyperLink)e.Item.FindControl("hyp_tt");

            Literal lit_Ma = (Literal)e.Item.FindControl("lit_Ma");
            HiddenField hf_id = (HiddenField)e.Item.FindControl("hf_id");

            HyperLink hyp_mactdh = (HyperLink)e.Item.FindControl("hyp_mactdh");


            tbChiTietDH  ctdh = tbChiTietDHBUS .GetByID(dd.IDCTDH );
            if (ctdh != null)
                hyp_mactdh.Text = ctdh.IDCTDH .ToString();


            lit_Ma.Text = dd.IDMSSP .ToString();
            hf_id.Value = dd.IDMSSP.ToString();

            hyp_dd.Text = dd.MaSo.ToString();
            hyp_tt.Text = dd.TrangThai .ToString();
            hyp_tt.NavigateUrl = "MaSoSPList.aspx";
            HyperLink hpl_Edit = (HyperLink)e.Item.FindControl("hpl_Edit");
            hpl_Edit.NavigateUrl = "MaSoSPUpdate.aspx?id=" + dd.IDMSSP .ToString();


        }

    }

}
